package handlers

import (
	"deliv-eat/models"
	"github.com/gin-gonic/gin"
)

func DeliAdd(c *gin.Context) {
	title := c.PostForm("title")
	content := c.PostForm("content")
	deli := models.DeLiv{
		Title:   title,
		Content: content,
	}
	err := models.DB.Create(&deli).Error
	if err != nil {
		c.JSON(200, gin.H{
			"coed": 0,
			"msg":  "添加失败",
		})
		return
	}
	c.JSON(200, gin.H{
		"coed": 200,
		"msg":  "添加成功",
	})
	return
}

func DeliList(c *gin.Context) {
	var deli []models.DeLiv
	err := models.DB.Find(&deli).Error
	if err != nil {
		c.JSON(200, gin.H{
			"coed": 0,
			"msg":  "查询失败",
		})
		return
	}
	c.JSON(200, gin.H{
		"coed": 200,
		"msg":  "查询成功",
	})
	return
}

func UserList(c *gin.Context) {
	var user []models.User
	err := models.DB.Find(&user).Error
	if err != nil {
		c.JSON(200, gin.H{
			"coed": 0,
			"msg":  "查询失败",
		})
		return
	}
	c.JSON(200, gin.H{
		"coed": 200,
		"msg":  "查询成功",
	})
	return
}
